import time

import cv2
import mediapipe as mp

cap = cv2.VideoCapture(0)
Ptime = 0
mpHangs = mp.solutions.hands
hands = mpHangs.Hands()
mpDraw = mp.solutions.drawing_utils

while True:
    ret,frame = cap.read()
    frameRGB = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
    results = hands.process(frameRGB)
    if results.multi_hand_landmarks:
        for handlms in results.multi_hand_landmarks:
            mpDraw.draw_landmarks(frame, handlms, mpHangs.HAND_CONNECTIONS)
            for id,lm in enumerate(handlms.landmark):
                h,w,c = frame.shape
                cx,xy = int(lm.x*w),int(lm.y*h)
                if id == 4:
                    cv2.circle(frame,(cx,xy),25,(255,0,255),cv2.FILLED)
                # cv2.circle(frame,(cx,xy),5,(255,0,255),cv2.FILLED)
    Ctime = time.time()
    fps = 1/(Ctime-Ptime)
    Ptime = Ctime
    cv2.putText(frame, f'fps:{int(fps)}', (10,70), cv2.FONT_HERSHEY_PLAIN, 3, (255,0,255), 2)
    cv2.imshow('frame',frame)
    cv2.waitKey(45)